package com.cowain.monitor.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.cowain.monitor.dao.ErpApDao;
import com.cowain.monitor.datasources.DataSourceNames;
import com.cowain.monitor.datasources.annotation.DataSource;
import com.cowain.monitor.entity.ErpApEntity;
import com.cowain.monitor.entity.ErpSoEntity;
import com.cowain.monitor.service.ErpApService;
import com.cowain.monitor.utils.PmsConstantUtils;
import com.cowain.monitor.utils.PmsProjectUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 *  
 *  * @author 冬暖
 *  * @projectName pms-monitor
 *  * @title     ErpApServiceImpl   
 *  * @package    com.cowain.monitor.service.impl  
 *  * @description    ERP回款状态       
 *  * @date   2020/7/28 13:28  
 *  * @version V1.0.0
 *  
 */
@Service
public class ErpApServiceImpl extends ServiceImpl<ErpApDao,ErpApEntity> implements ErpApService {
    @Autowired
    private PmsProjectUtil pmsProjectUtil;
    /**
     * 获取回款的信息
     * @return 回款信息
     */
    @Override
    @DataSource(name = DataSourceNames.SECOND)
    public List<ErpApEntity> findErpApList(){
        return baseMapper.findErpApList(PmsConstantUtils.IS_DEL);
    }

    /***
     * 保存数据
     */
    @Override
    @DataSource(name = DataSourceNames.FIRST)
    public void insertErpApList(List<ErpApEntity> entities){

    }
    /**
     * 修改状态
     */
    @Override
    public void updateErApList(List<ErpApEntity> erpApEntities){
        erpApEntities.forEach(ap -> ap.setIsDel(1));
        List<ErpApEntity> collect = erpApEntities.stream()
                .filter(s -> s.getIsDel() == 1)
                .collect(Collectors.toList());
        List<List<ErpApEntity>> split = pmsProjectUtil.split(collect, 12);
        for (List<ErpApEntity> apEntities : split) {
            baseMapper.updateErApList(apEntities);
        }

    }
}
